<?php 
    //－－－  获得post的数据  －－－
	$User = $_POST['UserID'];
	$isRequestPhoto = $_POST['isRequest'];
	$HeadPhoto = $_POST['HeadPhoto'];
	//－－－  连接服务器  －－－
    $con = mysql_connect("127.0.0.1:3306","root","1qazse4");
	$DataName = 'ShareNavigation';
	if(!$con)
	{
		die('无法连接远程服务器: '.mysql_error);
	}
	//－－－  链接指定数据库  －－－
	mysql_query("SET NAMES UTF8");
	mysql_select_db($DataName,$con);
	if($isRequestPhoto == 'TRUE')
	{
		$query = "SELECT HeadPhoto FROM User WHERE UserID = \"$User\"";
		$result = mysql_query($query);
		if(!$result)
		{
			die('FALSE');	
		}
		else 
		{
			$row = mysql_fetch_array($result);
			if($row['HeadPhoto'] == '')
			{
				echo 'NULL';
			}
			else
			{
				echo $row['HeadPhoto'];
			}
		}
	}
	//---  上传头像的  ----
	else 
	{
		 if((($_FILES["image"]["type"] == "image/png")
       		|| ($_FILES["image"]["type"] == "image/jpeg")
	   		|| ($_FILES["image"]["type"] == "image/jpg"))
       		)
    	{
    
        	if($_FILES["image"]["error"] > 0)
        	{
        		//---  输出错误信息  ---
            	echo "Error: " . $_FILES["image"]["error"];
        	}
        	else
        	{
             	if(file_exists("upload/" . $_FILES["image"]["name"]))
            	{
        	        echo  '请不要重复上传';
      	    	}
            	else
           		 {
            	    move_uploaded_file($_FILES["image"]["tmp_name"],
        	        "upload/" . $_FILES["image"]["name"]);
					$query = "UPDATE User SET HeadPhoto = \"$HeadPhoto\" WHERE UserID = \"$User\"";
					if (!mysql_query($query,$con))
  					{
  						//echo "AccountNumber". '<br />';
  						//---  如果数据库插入语句出错，就把已上传文件给删除   ---
  						$file = "upload/" . $_FILES["image"]["name"];
						unlink($file);
 						die('服务器错误: ' . mysql_error());
 					}
					else
					{
						echo 'TRUE';
					}
            	   // echo "Stored in: ". "upload/" . $_FILES["file"]["name"];
        	    }
    	    }
    	}
	}
	//关闭数据库连接
	
	mysql_close($con);
?>